package com.sc.test.smalltest;

import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.sc.test.R;
import com.sc.test.utils.Util;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Shen Chao.
 * Created on 2018-10-25.
 */
public class SmallTestActivity extends AppCompatActivity {
    @BindView(R.id.et_phone)
    EditText etPhone;
    @BindView(R.id.et_email)
    EditText etEmail;
    @BindView(R.id.et_data)
    EditText etData;
    @BindView(R.id.tv_result)
    TextView tvResult;
    private String result = "";

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_smalltest);
        ButterKnife.bind(this);
    }

    @OnClick({R.id.bt_show, R.id.bt_clear})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.bt_show:
                if (!TextUtils.isEmpty(etPhone.getText())) {
                    result = etPhone.getText().toString();
                    if (CheckDataUitls.isMobile(result)) {
                        tvResult.append(result);
                        tvResult.append("    ");
                    } else {
                        Util.toast(this, "手机号无效");
                    }
                }
                if (!TextUtils.isEmpty(etEmail.getText())) {
                    result = etEmail.getText().toString();
                    if (CheckDataUitls.isEmail(result)) {
                        tvResult.append(result);
                        tvResult.append("    ");
                    } else {
                        Util.toast(this, "邮箱无效");
                    }
                }
                if (!TextUtils.isEmpty(etData.getText())) {
                    result = etData.getText().toString();
                    if (CheckDataUitls.isPassword(result)) {
                        tvResult.append(result);
                        tvResult.append("    ");
                    } else {
                        Util.toast(this, "密码无效");
                    }
                }
                tvResult.append("\n");
                break;
            case R.id.bt_clear:
                tvResult.setText("");
                break;
        }
    }
}
